package com.atguigu.lease.common.aliyun;




import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(AliyunSMSProperties.class)
//条件加载
@ConditionalOnProperty(prefix = "aliyun.sms",name = "endpoint")
public class AliyunSMSConfiguration {
    @Autowired
    private AliyunSMSProperties aliyunSMSProperties;


    @Bean
    public Client createClient() throws Exception {
        Config config = new Config()
                // System.getenv()方法表示获取系统环境变量，请配置环境变量后，在此填入环境变量名称，不要直接填入AccessKey信息。
                // 配置 AccessKey ID
                .setAccessKeyId(aliyunSMSProperties.getAccessKeyId())
                // 配置 AccessKey Secret
                .setAccessKeySecret(aliyunSMSProperties.getAccessKeySecret())
                // 配置 Endpoint
                .setEndpoint(aliyunSMSProperties.getEndpoint());
        return new Client(config);
    }
}
